package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.anno.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.result.ResultCodeEnum;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.model.user.UserInfo;
import com.atguigu.tingshu.user.service.UserInfoService;
import com.atguigu.tingshu.user.service.UserListenProcessService;
import com.atguigu.tingshu.vo.user.UserListenProcessVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserInfoApiController {


	private final UserInfoService userInfoService;

	@Autowired
	public UserInfoApiController(UserInfoService userInfoService) {
		this.userInfoService = userInfoService;
	}
	/**
	 * @description: 查询用户信息通过用户id
	 * @author Petrichor
	 * @date 2023/12/29 9:03
	 * @param userId
	 * @return
	**/
	@GetMapping(value = "/findUserInfoByUserId/{userId}")
	public Result<UserInfo> findUserInfoByUserId(@PathVariable(value = "userId") Long userId) {
		UserInfo userInfo = userInfoService.getById(userId);
		return Result.build(userInfo , ResultCodeEnum.SUCCESS) ;
	}
	/**
	 * @description: 判断用户是否购买声音列表
	 * @author Petrichor
	 * @date 2024/1/1 15:28
	 * @param albumId 专辑id
	 * @return trackIdList 声音id列表
	**/
	@GuiGuLogin(required = true)
	@Operation(summary = "判断用户是否购买声音列表")
	@PostMapping("userIsPaidTrack/{albumId}")
	public Result<Map<Long, Integer>> userIsPaidTrack(@PathVariable Long albumId, @RequestBody List<Long> trackIdList) {
		Long userId = AuthContextHolder.getUserId();
		Map<Long, Integer> map = userInfoService.userIsPaidTrack(userId, albumId, trackIdList);
		return Result.ok(map);
	}
	/**
	 * @description: 判断用户是否购买过专辑
	 * @author Petrichor
	 * @date 2024/1/6 16:25
	 * @param albumId 专辑id
	 * @return 是否购买过专辑
	**/
	@GuiGuLogin
	@Operation(summary = "判断用户是否购买过专辑")
	@GetMapping("/isPaidAlbum/{albumId}")
	public Result<Boolean> isPaidAlbum(@PathVariable Long albumId) {
		Boolean flag = userInfoService.isPaidAlbum(albumId);
		return Result.ok(flag);
	}
	/**
	 * @description: 根据专辑id获取用户支付过的声音id列表
	 * @author Petrichor
	 * @date 2024/1/7 21:31
	 * @param albumId 专辑id
	 * @return 查看当前用户的 当前专辑购买的 声音集数 集合
	**/
	@GuiGuLogin
	@Operation(summary = "根据专辑id获取用户支付过的声音id列表")
	@GetMapping("/findUserPaidTrackList/{albumId}")
	public Result<List<Long>> findUserPaidTrackList(@PathVariable Long albumId){
		List<Long> trackIdList = userInfoService.findUserPaidTrackList(albumId);
		return Result.ok(trackIdList);
	}

	/**
	 * @description: 更新Vip到期失效状态
	 * @author Petrichor
	 * @date 2024/1/12 19:13
	 * @return NULL
	**/
	@Operation(summary = "更新Vip到期失效状态")
	@GetMapping("updateVipExpireStatus")
	public Result updateVipExpireStatus() {
		userInfoService.updateVipExpireStatus();
		return Result.ok();
	}
}

